<?php
namespace app\model;
use think\model;
use think\facade\Db;
class ArticleLab extends Model{

    protected $table = "user_articlelab";

    // 插入
    public function insertArticleLab($data,$uid,$id){
        $at = ArticleLab::Create([
            "uid"=>$uid,
            "atId"=>$id,
            "python"=>$data["python"],
            "java"=>$data["java"],
            "php"=>$data["php"],
            "C"=>$data["C"],
            "Go"=>$data["Go"],
            "Hadoop"=>$data["Hadoop"],
        ]);
        return $at;
    }


    // 标签更新
    public function saveArticleLab($data,$uid,$id){
        foreach ($data as $key=>$value){
            $artLab = new ArticleLab();
            $artLab->updateArticleLab($uid,$id,$key,$value);
        }
    }

    // 标签更新
    public function updateArticleLab($uid,$id,$key,$flag){
        ArticleLab::update([
            "$key"=>"$flag"
        ],[
            'atId'=>"$id",
            'uid'=>"$uid"
        ]);
    }


    function queryArtLab($id,$uid){
        $artLab = ArticleLab::where('atId',$id)->where('uid',$uid)->find();
        return $artLab;
    }

    // 删除
    function delAtById($id){
        Db::table('user_articlelab')->where('atId',$id)->delete();
    }
}